package com.icbc.api;

import com.icbc.api.request.QrcodeRejectRequestV2;
import com.icbc.api.request.QrcodeRejectRequestV2.QrcodeRejectRequestV2Biz;
import com.icbc.api.response.QrcodeRejectResponseV2;

/**
 * 工银二维码退款接口
 * 
 * 请商户配置SDK中的lib文件夹中的jar包后，根据备注1-6提示进行数据替换
 */
public class QrcodeRejectTest {
	public static void main(String[] args) throws Exception {
		//签名类型为RSA2时，需传入appid，私钥和网关公钥，签名类型使用定值IcbcConstants.SIGN_TYPE_RSA2，其他参数使用缺省值
		DefaultIcbcClient client = new DefaultIcbcClient(QrcodeConstants.APP_ID, IcbcConstants.SIGN_TYPE_RSA2, QrcodeConstants.MY_PRIVATE_KEY, QrcodeConstants.APIGW_PUBLIC_KEY);
		QrcodeRejectRequestV2 request = new QrcodeRejectRequestV2();
		//4、根据测试环境和生产环境替换相应ip和端口
		request.setServiceUrl(QrcodeConstants.QRCODE_REJECT_URL);
		//5、请对照接口文档用bizContent.setxxx()方法对业务上送数据进行赋值
		QrcodeRejectRequestV2Biz bizContent = new QrcodeRejectRequestV2Biz();
		bizContent.setMerId(QrcodeConstants.MER_ID);
		bizContent.setCustId("Ey0LsS39FwdE35aaadfsdfTsSW1A2eeoIRMZrjSb");//该字段非必输项
		bizContent.setOutTradeNo("X000000010");//该字段非必输项,out_trade_no和order_id选一项上送即可
		bizContent.setOrderId("020001515151201701030001112");//该字段非必输项,out_trade_no和order_id选一项上送即可
		bizContent.setRejectNo("X000011111");
		bizContent.setRejectAmt("200");
		bizContent.setOperId("X03");//该字段非必输项 ReturnMsg:字段biz_content.oper_id应满足条件:英文或数字，非必输项少于3位
		request.setBizContent(bizContent);

		QrcodeRejectResponseV2 response;
		try {
			response = client.execute(request, "urcnl24ciaauta9");//msgId消息通讯唯一编号，要求每次调用独立生成，APP级唯一
			if (response.isSuccess()) {
			    // 成功
			    System.out.println("====调用成功=====");
				// 6、业务成功处理，请根据接口文档用response.getxxx()获取同步返回的业务数据
				System.out.println("ReturnCode:"+response.getReturnCode());
				System.out.println("ReturnMsg:" + response.getReturnMsg());
				System.out.println("OrderId:" + response.getOrderId());
				System.out.println("RejectAmt:" + response.getRejectAmt());
				System.out.println("RejectBankDiscAmt:" + response.getRejectBankDiscAmt());
			} else {
				// 失败
			    System.out.println("====调用失败=====");
				System.out.println("ReturnCode:"+response.getReturnCode());
				System.out.println("ReturnMsg:"+response.getReturnMsg());
			}		
		} catch (IcbcApiException e) {
			e.printStackTrace();
		}
	}
}